package com.nexfra.bbssys.bbs.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nexfra.bbssys.bbs.dao.BbsGeneralBoardDao;
import com.nexfra.bbssys.common.domain.AttachFile;
  
@Service
public class BbsGeneralBoardService {
	private static final Logger logger = LoggerFactory.getLogger(BbsGeneralBoardService.class);
	
	@Autowired
	private BbsGeneralBoardDao dao;

	/**
	 * 게시판전체목록 카운트를 조회한다. 
	 * @return List<Map<String,Object>>
	 */
	public long selectGeneralBoardListCount(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.selectGeneralBoardListCount(sqlParams);
	}
	
	/**
	 * 게시판목록을 조회한다. 
	 * @return List<Map<String,Object>>
	 */
	public List<Map<String,Object>> selectGeneralBoardList(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.selectGeneralBoardList(sqlParams);
	}
	
	/**
	 * 게시글을 조회한다. 
	 * @return Map<String,Object>
	 */
	public Map<String,Object> selectGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.selectGeneralBoard(sqlParams);
	}
	
	/**
	 * 게시글 조회수를 업데이트한다. 
	 * @return int
	 */
	public void updateReadCntGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {
		dao.updateReadCntGeneralBoard(sqlParams);
	}	

	/**
	 * 게시글 댓글을 조회한다. 
	 * @return List<Map<String,Object>>
	 */
	public List<Map<String,Object>> selectGeneralBoardCmmt(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.selectGeneralBoardCmmt(sqlParams);
	}
	
	/**
	 * 게시글 첨부파일을 조회한다. 
	 * @return List<Map<String,Object>>
	 */
	public List<Map<String,Object>> selectGeneralBoardAtch(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.selectGeneralBoardAtch(sqlParams);
	}

	/**
	 * 게시글 첨부파일을 삭제한다.(논리적삭제) 
	 * @return int
	 */
	public int deleteGeneralBoardAtch(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.deleteGeneralBoardAtch(sqlParams);
	}
	
	/**
	 * 댓글을 삭제한다.(물리적삭제) 
	 * @return void
	 */
	public void deleteCommentGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {
		dao.deleteCommentGeneralBoard(sqlParams);
	}

	/**
	 * 게시글ID를 채번한다. 
	 * @return List<Map<String,Object>>
	 */
	public String selectSeqAtclId() throws Exception {
		return dao.selectSeqAtclId();
	}
	
	/**
	 * 댓글ID를 채번한다. 
	 * @return List<Map<String,Object>>
	 */
	public String selectSeqCmmtId() throws Exception {
		return dao.selectSeqCmmtId();
	}
	
	/**
	 * thead ID를 채번한다. 
	 * @return List<Map<String,Object>>
	 */
	public String selectSeqThread() throws Exception {
		return dao.selectSeqThread();
	}
	
	/**
	 * 댓글thead ID를 채번한다. 
	 * @return List<Map<String,Object>>
	 */
	public String selectSeqCmmtThread() throws Exception {
		return dao.selectSeqCmmtThread();
	}
	
	/**
	 * 파일첨부 ID를 채번한다. 
	 * @return List<Map<String,Object>>
	 */
	public String selectSeqAtchId() throws Exception {
		return dao.selectSeqAtchId();
	}

	/**
	 * 게시글을 등록한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void insertGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.insertGeneralBoard(sqlParams);
	}
	
	/**
	 * 댓글을 등록한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void insertCommentGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.insertCommentGeneralBoard(sqlParams);
	}
	
	/**
	 * 태그를 등록한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void insertAtclTagId(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.insertAtclTagId(sqlParams);
	}
	
	/**
	 * 게시글을 수정한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void updateGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.updateGeneralBoard(sqlParams);
	}
	
	/**
	 * 게시글을 삭제한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void deleteGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.deleteGeneralBoard(sqlParams);
	}	
	
	/**
	 * 게시글의 정렬순서를 수정한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void updateOrderSeqGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.updateOrderSeqGeneralBoard(sqlParams);
	}
	
	/**
	 * 댓글의 정렬순서를 수정한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void updateCommentOrderSeqGeneralBoard(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.updateCommentOrderSeqGeneralBoard(sqlParams);
	}
	
	/**
	 * 첨부파일을 등록한다.
	 * @param model
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void insertAtchFile(HashMap<String, String> sqlParams) 
			throws Exception {	
		dao.insertAtchFile(sqlParams);	
			
	}
	
	/**
	 * 게시글에 딸린 첨부파일 개수를 조회한다. 
	 * @return int
	 */
	public int selectGeneralBoardAtchCount(HashMap<String, String> sqlParams) 
			throws Exception {
		return dao.selectGeneralBoardAtchCount(sqlParams);
	}	
}
